#ifndef DIALOG_CAMADJUST_H
#define DIALOG_CAMADJUST_H

#include <QDialog>
#include <QTimer>

namespace Ui {
class Dialog_camAdjust;
}



class Dialog_camAdjust : public QDialog
{
    Q_OBJECT
public:
    enum comboBoxItem {
        Top = 0,
        Side,
        Null
    };

public:
    explicit Dialog_camAdjust(QWidget *parent = nullptr, comboBoxItem currItem = Null);
    ~Dialog_camAdjust();
    QByteArray formSetData(int speed,int angle,int radio);
    QByteArray intToByteArray(int value);
    void SetAngle(int angle);
//    void SetAngle(int16_t angle);



    static int topCamadjustValue;
    static int sideCamadjustValue;
    static int calculateFocusRotation(int currentFocus, int targetFocus);

    void initTimer();
signals:
    void sendTopAdjustData(QByteArray dat);
    void sendSideAdjustData(QByteArray dat);

    void returnData(int angle);
public slots:
    void getTopRecv(QByteArray data);
    void getSideRecv(QByteArray data);

    void do_disableAngleSet(bool state);
//    void sendSideFormSetData(int16_t angle);
    //    void sendTopFormSetData(int16_t angle);

private slots:

    void on_btn_ok_clicked();

    void on_btn_cancel_clicked();

//    void on_btn_set_clicked();

    void on_btn_angle_subtract_clicked();

    void on_btn_angle_add_clicked();
    void waitForTime(int finishTime, int intervalTime=1000);
//    void on_pushButton_clicked();

    void onTimeout();
    void topSetAngle(int &angle);
    void sideSetAngle(int &angle);
//    void on_lineEdit_stepWidth_textChanged(const QString &arg1);

protected:
    void mousePressEvent(QMouseEvent *event) override;
private:
    Ui::Dialog_camAdjust *ui;

    QTimer *m_btn_timer = nullptr;

    int m_speed = 40;  // 速度固定为40
    int m_radio = 16384;// 分辨率固定为16384
    int m_angle;

    int m_currentAngle;
    comboBoxItem m_currItem;



//    QString m_AngleMinVal = "0";
//    QString m_AngleMaxVal = "360";

    bool m_thisTimePn = false;
    bool m_lastTimePn = false;

    bool m_thisTimePnTop = false;
    bool m_lastTimePnTop = false;

    bool m_thisTimePnSide = false;
    bool m_lastTimePnSide = false;

    QTimer *m_timer = nullptr;
};

#endif // DIALOG_CAMADJUST_H
